/**
 * <copyright>
 * Copyrigth 2007 Aurelien Moreau
 *
 * This file is part of ProcessShop.
 *
 * ProcessShop is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * ProcessShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with ProcessShop; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * </copyright>
 *
 * $Id$
 */
package net.yienyien.process.bpel.generator.controlFlow;

import net.yienyien.process.bpd.BPDModel;
import net.yienyien.process.bpel.generator.BPELGenerationException;
import net.yienyien.process.bpel.generator.Contrib;
import net.yienyien.process.bpel.generator.ContribImpl;
import net.yienyien.process.bpel.generator.Production;
import net.yienyien.process.folder.BPDFolder;
import net.yienyien.process.folder.BPDFolderFactory;
import net.yienyien.process.folder.stdPatterns.StdPatternsFactory;

import org.eclipse.emf.ecore.EObject;

public class ControlFlowContrib extends ContribImpl implements Contrib {

	public static final String KEY="ControlFlowContrib";
	
	private BPDModel bpd;
	
	public ControlFlowContrib() {
	}
	
	@Override
	public String getContribKey() {
		return KEY; 
	}
	
	@Override
	public void prepare(Production data, EObject contribution) {
		BPDFolder folder=getGenerator().getFolder();
		folder.addPattern(StdPatternsFactory.eINSTANCE.createFlow());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createPick());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createSequence());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createSwitch());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createRepeat());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createWhile());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createRepeatWhile());
		folder.addPattern(StdPatternsFactory.eINSTANCE
				.createSynchronizingProcess());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createOther());
		getGenerator().getFolder().addListener(new ControlFlowContribListener(data));
		bpd=(BPDModel) contribution;
	}

	@Override
	public void contrib() throws BPELGenerationException {
		getGenerator().getFolder().loopFold(bpd);
	}
}
